# == Class: base
#
# Full description of class base here.
#
# === Parameters
#
# Document parameters here.
#
# [*sample_parameter*]
#   Explanation of what this parameter affects and what it defaults to.
#   e.g. "Specify one or more upstream ntp servers as an array."
#
# === Variables
#
# Here you should define a list of variables that this module would require.
#
# [*sample_variable*]
#   Explanation of how this variable affects the funtion of this class and if
#   it has a default. e.g. "The parameter enc_ntp_servers must be set by the
#   External Node Classifier as a comma separated list of hostnames." (Note,
#   global variables should be avoided in favor of class parameters as
#   of Puppet 2.6.)
#
# === Examples
#
#  class { base:
#    servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
#  }
#
# === Authors
#
# Author Name <author@domain.com>
#
# === Copyright
#
# Copyright 2014 Your name here, unless otherwise noted.
#
class base (
  $puppetinterval     = $base::params::puppetinterval,
  $enable_biosdevname = $base::params::enable_biosdevname,
  $enable_ipshow      = $base::params::enable_ipshow,
  $permitrootlogin    = $base::params::permitrootlogin,
  $timezone           = $base::params::timezone,
  
)inherits base::params {
  #if versioncmp($::puppetversion,'3.6.1') >= 0 {

  #$allow_virtual_packages = hiera('allow_virtual_packages',false)

  #Package {
  #  allow_virtual => $allow_virtual_packages,
  #}
  #}
  if $enable_ipshow { 
    notify {"Node IP is: ${facts['networking']['ip']}":} 
  }
  file {'/root/bin':
    ensure   => "directory",
    owner    => 0,
    group    => 0,
    mode     => '0755',
  }
  
  class { 'timezone':
    timezone => $timezone,
  }
  cron { create_facter:
    command => 'rm -f /root/facter ; /opt/puppetlabs/bin/facter -j | tr -d "\n"  > /root/facter; sed -i "1s/$/\n/" /root/facter',
    user    => 'root',
    minute  => '40',
    hour    => '02',
  }

  cron { clean_puppetlock:
    command => 'find /var/lib/puppet/state/agent_catalog_run.lock -ctime +1 -maxdepth 1  -exec rm -f {} \;',
    user    => 'root',
    minute  => 44,
    hour    => '*/6',
  }

  exec { " rebuid_rpmdb":
     command => "/bin/rpmdb --rebuilddb",
     path => "/bin/rpm",
     unless => "/bin/rpm -q  kernel ",
  }

    include '::base::puppetconf'
    #include '::base::kernel'
  sshd_config { 'PermitRootLogin':
    ensure => present,
    value  => $permitrootlogin,
    notify => Service['sshd'],
  }
  service { "sshd":
    ensure     => running,
    hasstatus  => true,
    hasrestart => true,
    enable     => true,
  }

  # for 24 hours:
  augeas{"LC_TIME" :
   context => "/files/etc/locale.conf",
   changes => "set LC_TIME en_GB.UTF-8",
  }

 
  ### This is for mail command working
  if $facts['os']['release']['major'] >= '9' {
    package{ "postfix":
      ensure   => installed,
      require  => Yumrepo['site']
    } ->
    service { "postfix":
      ensure   => running,
      hasstatus  => true,
      hasrestart => true,
      enable     => true,
    }
  }
}
